package com.thy.controller;


import com.hospital.common.base.PageResult;
import com.hospital.common.base.Result;
import com.hospital.common.base.ThreadAttributes;
import com.hospital.common.dto.audit.module.DeletePostDto;
import com.hospital.common.dto.audit.module.PostReviewDto;
import com.hospital.common.utils.ThreadLocalUtils;
import com.hospital.common.vo.audit.module.PostVo;
import com.thy.service.TPostMetaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 帖子元数据表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-26
 */
@RestController
@RequestMapping("/postMeta")
public class TPostMetaController {
    @Autowired
    private TPostMetaService tPostMetaService;

    /**
     * 审核是否有敏感词
     * @param content
     * @return 200没有敏感词 -1有敏感词
     */
    @GetMapping("/getViolation")
    public Result<Integer> getViolation(@RequestParam("content")String  content){
        Integer code = tPostMetaService.getViolation(content);
        return Result.success(code);
    }

    /**
     * 查询所有待审核帖子
     * @param pageNum
     * @param pageSize
     * @return PageResult<PostVo>
     */
    @GetMapping("/getPost")
    public Result<PageResult<PostVo>> getPost(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize){
        ThreadAttributes threadAttributes = ThreadLocalUtils.get();
        Long userId = threadAttributes.getUserId();
        PageResult<PostVo> pageResult = tPostMetaService.getPost(pageNum, pageSize,userId);
        return Result.success(pageResult);
    }

    /**
     * 帖子审核
     * @param postReviewDto
     * @return String
     */
    @PostMapping("/postReview")
    public Result<String> postReview(@RequestBody PostReviewDto postReviewDto){
        tPostMetaService.postReview(postReviewDto);
        return Result.success(1,"审核成功!");
    }

    /**
     * 删除帖子
     * @param dpd
     * @return  String
     */
    @PostMapping("/deletePost")
    public Result<String> deletePost(@RequestBody DeletePostDto dpd){
        tPostMetaService.deletePost(dpd);
        return Result.success(1,"删除成功!");
    }

}
